package com.haoziqi.chapter_05;

import org.apache.flink.api.common.functions.RichFilterFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Arrays;

/**
 * description
 * created by A on 2021/3/4
 */
public class FilterTrans {
    public static void main(String[] args) {
        //1.创建环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<Integer> i = env.fromCollection(Arrays.asList(1, 2, 3, 4, 5, 6));
        i.filter(
                new RichFilterFunction<Integer>() {
                    @Override
                    public boolean filter(Integer value) throws Exception {
                        if(value%2!=0){
                            return true;
                        }else{
                            return false;
                        }
                    }
                }
        ).print().setParallelism(1);
        //提交任务
        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
